
import { reqUserLogin } from '@/api/user'
export default {
  // 独立命名空间锁
  namespaced: true,
  // 用户模块数据
  state: () => {
    return {
      // 用户资料
      profile: {
        id: '',
        nickname: '',
        token: ''
      }
    }
  },
  mutations: {
    // 存用户信息
    setProfile (state, form) {
      console.log(999)
      state.profile = form
    },
    // 清空用户信息
    clearProfile (state) {
      state.profile = {
        id: '',
        nickname: '',
        avatar: '',
        token: '',
        mobile: ''
      }
    }
  },
  actions: {
    // 登录异步请求
    async login (store, form) {
      const { result } = await reqUserLogin(form)
      console.log(result)
      store.commit('setProfile', result)
    }
  }
}
